<include file="public@header"/>

</head>
<body>
    <div class="layui-fluid js-check-wrap">
        <div class="layui-card">
            <div class="layui-card-header">
                <h3>{:lang('GOODS_ADMINGOODSATTRIBUTE_INDEX')}</h3>
            </div>
            <div class="layui-card-body">
                <form class="form-search layui-form clearfix" action="{:url('AdminGoodsAttribute/index')}">
                    <div class="layui-col-md11 layui-col-sm10">
                        <div class="layui-inline">
                            <label class="layui-form-label">{:lang('CAT_NAME')}：</label>
                            <div class="layui-input-inline">
                                <select class="layui-input" name="goods_type" >
                                    <option value=''>全部类型</option>
                                    {$goods_type_list|default=''}
                                </select>
                            </div>
                        </div>

                        <!-- 用于列表排序 -->
                        <input type="hidden" name="sort_by" value="{$filter.sort_by}">
                        <input type="hidden" name="list_order" value="{$filter.list_order}">
                        <!-- 用于列表排序 -->

                        <div class="layui-inline">
                            <input type="submit" class="layui-btn layui-btn-normal" value="{:lang('SEARCH')}"/>
                        </div>
                        <div class="layui-inline">
                            <a class="layui-btn layui-btn-danger" href="{:url('AdminGoodsAttribute/index')}">清空</a>
                        </div>
                    </div>

                    <div class="layui-col-md1 layui-col-sm2">
                        <a class="layui-btn layui-btn-normal fr" href="{:url('AdminGoodsAttribute/add',array('goods_type'=>$goods_type))}">{:lang('GOODS_AdminGoodsAttribute_ADD')}</a>
                    </div>
                </form>
            </div>
            <form method="post" class="js-ajax-form" action="{:url('AdminGoodsAttribute/listOrder')}">
                <table class="layui-table">
                    <thead>
                        <tr>
                            <th width="20" class="text-center">
                                <div class="custom-checkbox">
                                    <input type="checkbox" id="checkall" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                                    <label for="checkall"></label>
                                </div>
                            </th>
                            <th width="55"><a href="javascript:list_sort('list_order');">{:lang('SORT')}</a>{$sort_list_order}</th>
                            <!-- <th width="50"><a href="javascript:list_sort('attr_id'); ">ID</a>{$sort_attr_id}</th> -->
                            <th><a href="javascript:list_sort('attr_name'); ">{:lang('ATTR_NAME')}</a>{$sort_attr_name}</th>
                            <th><a href="javascript:list_sort('cat_id'); ">{:lang('CAT_NAME')}</a>{$sort_cat_id}</th>
                            <th><a href="javascript:list_sort('attr_input_type'); ">{:lang('ATTR_INPUT_TYPE')}</a>{$sort_attr_input_type}</th>
                            <th>{:lang('ATTR_VALUE')}</th>
                            <th width="94">{:lang('ACTIONS')}</th>
                        </tr>
                    </thead>
                    <tbody>
                        <foreach name="list" item="vo">
                            <tr>
                                <td class="text-center">
                                    <div class="custom-checkbox">
                                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]" id="chk_{$vo.attr_id}"
                                           value="{$vo.attr_id}" title="ID:{$vo.attr_id}">
                                        <label for="chk_{$vo.attr_id}"></label>
                                    </div>
                                </td>

                                <td><input name="list_orders[{$vo.attr_id}]" class="input input-order" type="text" size="5" value="{$vo.list_order}"></td>
                                <!-- <td>{$vo.attr_id}</td> -->
                                <td><span class="inline-block">{$vo.attr_name}</span></td>
                                <td>{$vo.cat_name}</td>
                                <td>{$vo.attr_input_type_desc}</td>
                                <td>{$vo.attr_values}</td>
                                <td>
                                    <a class="layui-btn layui-btn-xs" href="{:url('AdminGoodsAttribute/edit',array('attr_id'=>$vo['attr_id']))}">{:lang('EDIT')}</a>
                                    <a href="{:url('AdminGoodsAttribute/delete',array('attr_id'=>$vo['attr_id']))}" class="delete_attr layui-btn layui-btn-danger layui-btn-xs" data-id="{$vo['attr_id']}">{:lang('DELETE')}</a>
                                </td>
                            </tr>
                        </foreach>
                    </tbody>
                </table>

                <div class="pagination-row clearfix">
                    <div class="layui-col-sm6 text-left-sm">
                        <!-- 排序 -->
                        <if condition="cmf_auth_check(cmf_get_current_admin_id(), 'goods/AdminGoodsAttribute/listOrder')">
                            <button class="layui-btn layui-btn-warm  js-ajax-submit" type="submit"
                                    data-action="{:url('AdminGoodsAttribute/listOrder')}">{:lang('SAVE_SORT')}
                            </button>
                        </if>

                        <!-- 删除选中项 -->
                        <button class="layui-btn layui-btn-danger  js-ajax-submit" type="submit"
                                data-action="{:url('AdminGoodsAttribute/delete')}" data-subcheck="true" data-msg="{:lang('确定要删除吗？')}">
                            {:lang('DELETE_SELECTED')}
                        </button>
                    </div>
                    <div class="pages">{$page|default=''}</div>
                </div>
            </form>
        </div>
    </div>

<include file="public@footer"/>
<include file="public@listtable"/>
<script>
    /*ajax请求，删除产品属性*/
    $('.delete_attr').on('click',function(){
        var id   = $(this).attr('data-id');   /*要删除的属性id*/
        var href = this.href;                 /*执行删除的地址*/

        /*ajax请求，获取某属性商品数量*/
        $.get("{:url('AdminGoodsAttribute/getAttrNum')}",{'attr_id':id}, function(data){
            /*请求成功*/
            if(data.code == 1){
                /*弹窗*/
                layer.confirm(data.msg, {
                    title:'提示',
                    icon: 3,
                    btn: ['确定','取消'] //可以无限个按钮
                }, function(index, layero){
                    /*若点击确定，则执行删除*/
                    $.getJSON(href).done(function (data) {
                        /*删除成功，页面跳转*/
                        if (data.code === 1) {
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 1500 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                if (data.url) {
                                    location.href = data.url;
                                } else {
                                    reloadPage(window);
                                }
                            });

                        } else if (data.code === 0) {
                            layer.msg(data.msg);
                        }
                    });
                });

                // Wind.use("artDialog", function() {
                //     art.dialog({
                //         title: false,
                //         icon: 'question',
                //         content: data.msg,
                //         okVal: "确定",
                //         ok: function () {
                //             /*若点击确定，则执行删除*/
                //             $.getJSON(href).done(function (data) {
                //                 /*删除成功，页面跳转*/
                //                 if (data.code === 1) {
                //                     if (data.url) {
                //                         location.href = data.url;
                //                     } else {
                //                         reloadPage(window);
                //                     }
                //                 } else if (data.code === 0) {
                //                     artdialog_alert(data.msg);
                //                 }
                //             });
                //         },
                //         cancelVal: '取消',
                //         cancel: true
                //     });
                // });
            }
            /*else {
                artdialog_alert('删除失败！');
            }*/
        },'JSON');
        return false;
    });

</script>


